package cn.wen.yinxiu.system.service.impl;

import cn.wen.yinxiu.common.convention.errorcode.ErrorCode;
import cn.wen.yinxiu.common.convention.exception.ServiceException;
import cn.wen.yinxiu.system.dao.CloudConfigDao;
import cn.wen.yinxiu.system.entity.CloudConfigEntity;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.toolkit.Query;

import cn.wen.yinxiu.system.dao.SysConfigDao;
import cn.wen.yinxiu.system.entity.SysConfigEntity;
import cn.wen.yinxiu.system.service.SysConfigService;


@Service("sysConfigService")
public class SysConfigServiceImpl extends ServiceImpl<SysConfigDao, SysConfigEntity> implements SysConfigService {

    @Autowired
    private SysConfigDao sysConfigDao;

    @Autowired
    private CloudConfigDao cloudConfigDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SysConfigEntity> page = this.page(
                new Query<SysConfigEntity>().getPage(params),
                new QueryWrapper<SysConfigEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public CloudConfigEntity getConfigCloudInfo() {
        // 1.获取系统配置选择的云存储方式
        QueryWrapper<SysConfigEntity> sysConfigQueryWrapper = new QueryWrapper<>();
        sysConfigQueryWrapper.eq("id", 1);
        SysConfigEntity sysConfigEntity = sysConfigDao.selectOne(sysConfigQueryWrapper);
        Integer cloudId = sysConfigEntity.getUploadCloudId();

        // 2.通过获取的Id获取云配置的全部信息
        CloudConfigEntity target = cloudConfigDao.selectById(cloudId);
        return target;
    }

}